<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>

<script>
import requests from "./api/ajax";
export default {
  name: "App",

  data() {
    return {
      res: {},
    };
  },

  mounted() {
    if (!this.$cookie.get("userId")) {
      this.$router.push("/login");
    }
    if (this.$cookie.get("userId")) {
      this.getUser()
this.getCartCount();
    }
  
    // let url2 = "https://order.imooc.com/pay/cartorder";
    // mockRequests.get('/banner').then((data) => {
    //   console.log(data)
    //   this.res = data
    // })
    // requests.get('/mock/banner.json').then((data) => {
    //   console.log(data)这里的request不加base api
    // })
    // this.axios.get('/mock/banner.json').then((data) => {
    //   console.log(data)
    // })
  },
  methods: {
    getCartCount() {
      requests.get("/carts/products/sum").then((res=0) => {
        this.$store.dispatch("saveCartCount", res.data);
      });
    },

    getUser() {
      requests.get("/user").then((res) => {
        console.log(res);
        this.$store.dispatch("saveUserName", res.data.username);
        //  this.username = res.username
      });
    },
  },
};
</script>

<style lang="scss" scoped>
/* @import './assets/scss/reset.scss';
 
@import './assets/scss/base.scss';
@import './assets/scss/button.scss'; */
 
</style>
